<?php
     include_once('../src/classes/class.mysql.php');
    
     $comtec_id_order = $_POST['comtec_id_order'];
     $token = $_POST['token'];
     $type = $_POST['type']; 
     
     //TODO validar el token recibido por POST y el de la sesion.
     
     $db = new MySQL();  
     $tsql = "UPDATE orders SET status_reg=0 WHERE 
              comtec_id_order=".$comtec_id_order;
     if($db->query($tsql))
     { 
      $tsql = "UPDATE operation SET status_reg=0 WHERE 
               comtec_id_order=".$comtec_id_order;  
      $db->query($tsql);
      if ($type == 1){
       $result = $db->fetch_array($db->query("SELECT comtec_id_machine FROM orders WHERE comtec_id_order = $comtec_id_order"));
       $comtec_id_machine = $result['comtec_id_machine'];
       echo "<script>loadOrders($comtec_id_machine);</script>";
      }elseif($type == 2){
       echo "<script>loadHome();</script>";   
      }elseif($type == 3){
       echo "<script>searchOperations();</script>";    
      }
     }
     else
     {
      echo '<p class="error">';
      echo "Error al eliminar la operacion \n";  
      echo '</p';              
     }
?>
